package interview.data_structure;

/**
 * @author fance
 * @date 2018/7/14 15:50
 */
class NodeIII<E> {
    NodeIII next;
    E data;

    public NodeIII(E data) {
        this.data = data;
    }
}
public class MyQueue<E> {
    private NodeIII<E> head = null;
    private NodeIII<E> tail = null;


    public boolean isEmpty() {
        return head == tail;
    }

    public void offer(E data) {
        NodeIII<E> newNode = new NodeIII<>(data);
        if (head == null && tail == null) {
            head = tail = newNode;
        } else {
            tail.next = newNode;
            tail = newNode;
        }
    }

    public E poll() {
        if (isEmpty()) {
            return null;
        }
        E data = head.data;
        head = head.next;
        return data;
    }
}
